package com.bcbim.common.compress;

/**
 * @Description:
 * @Author: ye
 * @Date: 2022/7/6
 * @Version: V1.0
 **/
public class Dictionary {
    private Node head;
    private Node tail;
    private int size;

    public Dictionary() {
        head = null;
        tail = null;
        size = 0;
    }

    public void addNode(byte b) {
        Node val = new Node(b);
        if (head == null) {
            head = val;
            head = val;
            tail = val;
        }
        tail.setNext(val);
        tail = val;
        size++;
    }

    public boolean checkEquals(byte[] goal) {
        if (goal.length != this.size) {
            return false;
        }
        Node node = head;
        for (int i = 0; i < goal.length; i++) {
            if (goal[i] != node.getValue()) {
                return false;
            }
            node = node.getNext();
        }
        return true;
    }

}
